﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using CrystalDecisions.Shared;//负责解释TableLogOnInfo类
using CrystalDecisions.CrystalReports.Engine;//负责解释ReportDocument类

public partial class CrystalReport_CrystalReportMonStatus : System.Web.UI.Page
{
    public string ResponseHTML;
    protected void Page_Load(object sender, EventArgs e)
    {
        //Session["UserId"] = "6";
        //Session["UserName"] = "ximen";
        //Session["UserType"] = "辖区房管所";
        //Session["UserStreet"] = "西门";

        if (!IsPostBack)
            BindDate();
        if (Session["UserId"] != null)
        {
            if (!hasCache())
            {
                ResponseHTML = "";
                CrystalReportViewer1.Visible = true;
                bindRPT(); 
            }
            else
            {
                ResponseHTML = getCache();
                CrystalReportViewer1.Visible = false;
                CrystalReportSource1 = null;
            }
        }
        else {
            WebHelper.AlertAndRedirect("登陆超时，请重新登陆", "../Login.aspx");
        }
    }
    private string getCache()
    {
        string street = Session["UserStreet"].ToString();
        string effectdate = ddlyear.SelectedValue + ddlmonth.SelectedValue;
        string sqlt = "SELECT HTML from [MonthStatCache] where street='" + street + "' and effectdate=" + effectdate;
        return Server.UrlDecode(Convert.ToString(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sqlt)));
    }
    private bool hasCache()
    {
        string street = Session["UserStreet"].ToString();
        string effectdate = ddlyear.SelectedValue + ddlmonth.SelectedValue;
        string sqlt = "SELECT count(*) as b from [MonthStatCache] where street='" + street + "' and effectdate=" + effectdate;
        int isCache = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sqlt));
        if (isCache == 0)
            return false;
        else
            return true;
    }
    private void insertCache()
    {

        string html = Request["HTML"];
        html = html.Replace("'", "\"");
        html = Server.UrlEncode(html);
        string street = Session["UserStreet"].ToString();
        string effectdate = ddlyear.SelectedValue + ddlmonth.SelectedValue;
        string sql = "delete from [MonthStatCache] where [street]='" + street + "' and [EffectDate]=" + effectdate;
        SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, sql);
        sql = "INSERT INTO  [MonthStatCache] ([HTML] ,[street],[EffectDate]) values ('" + html + "','" + street + "'," + effectdate + ")";
        int i = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, sql);
        if (i == 1)
            WebHelper.AlertAndRefresh("保存成功");
        else
            WebHelper.Alert("保存失败");
    }
    private void bindRPT()
    {
        //使用报表对象加载报表
        string reportPath = Server.MapPath("~/CrystalReport/CrystalReportMonStatus.rpt");

        ParameterFields paramFields = new ParameterFields();
        ParameterField paramField = new ParameterField();
        ParameterDiscreteValue pdValue = new ParameterDiscreteValue();

        paramField.ParameterFieldName = "UpMan";
        string ddlstreetName = "";
        if (Session["UserStreet"].ToString() == "海曙")
        {
            ddlstreet.Visible = true;
            lblstreet.Visible = true;
            ddlstreetName = ddlstreet.SelectedValue;
        }
        else
        {
            ddlstreetName = Session["UserStreet"].ToString();
        }
        pdValue.Value = ddlstreetName.ToString();
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //时间参数
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "uptime";
        pdValue.Value = "(" + ddlyear.SelectedValue + "年" + ddlmonth.SelectedValue + "月)";
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月
        int thisMonth = Convert.ToInt32(ddlyear.SelectedValue + ddlmonth.SelectedValue);
        //上月
        int lastMonth;
        if (ddlmonth.SelectedValue == "01")
            lastMonth = thisMonth - 100 + 11;
        else
            lastMonth = thisMonth - 1;


        //string cmdtext2 = "SELECT dbo.getDiBaoZhengCount(\'" + searchTimes2 + "\',\'" + ddlstreetName.ToString() + "\','扶助证',0)"; //扶助上月


        string sql;

        //上月补贴人数
        sql = "SELECT dbo.getSubsidyRecordCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        int lastMonSubCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonSubCount";
        pdValue.Value = lastMonSubCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月补贴金额
        sql = "SELECT dbo.getSubsidyRecordTotalMoney(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonSubMoneySum = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonSubMoneySum";
        pdValue.Value = lastMonSubMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月补贴人数
        sql = "SELECT dbo.getSubsidyRecordCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonSubCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonSubCount";
        pdValue.Value = thisMonSubCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月补贴金额
        sql = "SELECT dbo.getSubsidyRecordTotalMoney(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonSubMoneySum = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonSubMoneySum";
        pdValue.Value = thisMonSubMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);



        //本月补贴人数增加
        sql = "SELECT dbo.getSubsidyRecordAddCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonSubCountAdd = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonSubCountAdd";
        pdValue.Value = thisMonSubCountAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月补贴金额增加
        sql = "SELECT dbo.getSubsidyRecordMoneyAdd(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)+dbo.getSubsidyRecordChangeMoneyAdd(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonSubMoneyAdd = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonSubMoneyAdd";
        pdValue.Value = thisMonSubMoneyAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月补贴人数减少
        sql = "SELECT dbo.getSubsidyRecordCountCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonSubCountCut = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonSubCountCut";
        pdValue.Value = thisMonSubCountCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月补贴金额减少
        sql = "SELECT dbo.getSubsidyRecordMoneyCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)+dbo.getSubsidyRecordChangeMoneyCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonSubMoneyCut = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonSubMoneyCut";
        pdValue.Value = thisMonSubMoneyCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月补贴补发户数
        sql = "SELECT dbo.getAddSubsidyNumCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonAddSubsidyNumCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonAddSubsidyNumCount";
        pdValue.Value = thisMonAddSubsidyNumCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月补贴补发金额
        sql = "SELECT dbo.getAddSubsidyNumSum(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonAddSubsidyNumSum = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonAddSubsidyNumSum";
        pdValue.Value = thisMonAddSubsidyNumSum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);





        //本年补贴人数
        sql = "SELECT dbo.getSubsidyRecordCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        int thisYearSubCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisYearSubCount";
        pdValue.Value = thisYearSubCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本年补贴金额
        sql = "SELECT dbo.getSubsidyRecordTotalMoney(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        //Response.Write(getSubsidyRecordTotalMoneySQL);
        //Response.End();
        double thisYearSubMoneySum = Convert.ToDouble(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        sql = "SELECT dbo.getAddSubsidyNumSum(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        double thisYearAddSubMoneySumD = Convert.ToDouble(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisYearSubMoneySum";
        pdValue.Value = thisYearSubMoneySum + thisYearAddSubMoneySumD;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

















        //上月减免人数
        sql = "SELECT dbo.getReduceRecordCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        int lastMonRedCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonRedCount";
        pdValue.Value = lastMonRedCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月减免金额
        sql = "SELECT dbo.getReduceRecordTotalMoney(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonRedMoneySum = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonRedMoneySum";
        pdValue.Value = lastMonRedMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月减免人数
        sql = "SELECT dbo.getReduceRecordCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonRedCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonRedCount";
        pdValue.Value = thisMonRedCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月减免金额
        sql = "SELECT dbo.getReduceRecordTotalMoney(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonRedMoneySum = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonRedMoneySum";
        pdValue.Value = thisMonRedMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);



        //本月减免人数增加
        sql = "SELECT dbo.getReduceRecordAddCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonRedCountAdd = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonRedCountAdd";
        pdValue.Value = thisMonRedCountAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月减免金额增加
        sql = "SELECT dbo.getReduceRecordMoneyAdd(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)+dbo.getReduceRecordChangeMoneyAdd(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonRedMoneyAdd = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonRedMoneyAdd";
        pdValue.Value = thisMonRedMoneyAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月减免人数减少
        sql = "SELECT dbo.getReduceRecordCountCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonRedCountCut = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonRedCountCut";
        pdValue.Value = thisMonRedCountCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月减免金额减少
        sql = "SELECT dbo.getReduceRecordMoneyCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        double thisMonRedMoneyCut = Convert.ToDouble(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonRedMoneyCut";
        pdValue.Value = thisMonRedMoneyCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本年减免人数
        sql = "SELECT dbo.getReduceRecordCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisYareRedCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisYareRedCount";
        pdValue.Value = thisYareRedCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本年减免金额
        sql = "SELECT dbo.getReduceRecordTotalMoney(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisYearRedMoneySum = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisYearRedMoneySum";
        pdValue.Value = thisYearRedMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);




        //上月实物配租人数
        sql = "SELECT dbo.getKindRecordCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonKinCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonKinCount";
        pdValue.Value = lastMonKinCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月实物配租面积
        sql = "SELECT dbo.getKindRecordAreaSum(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonKinArea = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonKinArea";
        pdValue.Value = lastMonKinArea;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);





        //本月实物配租人数
        sql = "SELECT dbo.getKindRecordCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonKinCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonKinCount";
        pdValue.Value = thisMonKinCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);
        //本月实物配租面积
        sql = "SELECT dbo.getKindRecordAreaSum(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        double thisMonKinArea = Convert.ToDouble(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonKinArea";
        pdValue.Value = thisMonKinArea;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);
        //本月实物配租人数增加
        sql = "SELECT dbo.getKindRecordAddCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonKinCountAdd = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonKinCountAdd";
        pdValue.Value = thisMonKinCountAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月实物配租面积增加
        sql = "SELECT dbo.getKindRecordMoneyAdd(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonKinAreaAdd = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonKinAreaAdd";
        pdValue.Value = thisMonKinAreaAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);




        //本月实物配租人数减少
        sql = "SELECT dbo.getKindRecordCountCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonKinCountCut = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonKinCountCut";
        pdValue.Value = thisMonKinCountCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月实物配租面积减少
        sql = "SELECT dbo.getKindRecordMoneyCut(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonKinAreaCut = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonKinAreaCut";
        pdValue.Value = thisMonKinAreaCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);



        //本年实物配租人数
        sql = "SELECT dbo.getKindRecordCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisYearKinCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisYearKinCount";
        pdValue.Value = thisYearKinCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本年实物配租面积
        sql = "SELECT dbo.getKindRecordAreaSum(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        double thisYearKindArea = Convert.ToDouble(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisYearKindArea";
        pdValue.Value = thisYearKindArea;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);





        //上月最低家庭数
        sql = "SELECT dbo.getLowestCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonZuiDiShouRuCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonZuiDiShouRuCount";
        pdValue.Value = lastMonZuiDiShouRuCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);



        //上月低保证
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',\'低保证\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonDiBaoCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonDiBaoCount";
        pdValue.Value = lastMonDiBaoCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月扶助证
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',\'扶助证\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonFuZhuCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonFuZhuCount";
        pdValue.Value = lastMonFuZhuCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //上月特困证
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',\'特困证\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonTeKunCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonTeKunCount";
        pdValue.Value = lastMonTeKunCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);






        //本月低保证
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',\'低保证\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonDiBaoCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonDiBaoCount";
        pdValue.Value = thisMonDiBaoCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月扶助证
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',\'扶助证\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonFuZhuCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonFuZhuCount";
        pdValue.Value = thisMonFuZhuCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月特困证
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',\'特困证\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonTeKuCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonTeKuCount";
        pdValue.Value = thisMonTeKuCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);



        //上月低收入人数 合计
        sql = "SELECT dbo.getZuiDiShouRuZhengCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\','低收入家庭',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonDiShouRuCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonDiShouRuCount";
        pdValue.Value = lastMonDiShouRuCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //上月低收入2人数以上
        sql = "SELECT dbo.getLowerCountTwoMore(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonDiShouRu1Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonDiShouRu1Count";
        pdValue.Value = lastMonDiShouRu1Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月低收入1人数
        sql = "SELECT dbo.getLowerCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonDiShouRu2Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonDiShouRu2Count";
        pdValue.Value = lastMonDiShouRu2Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);




        //本月低收入人数 合计
        sql = "SELECT dbo.getLowerCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonDiShouRuCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonDiShouRuCount";
        pdValue.Value = thisMonDiShouRuCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月低收入2人数以上
        sql = "SELECT dbo.getLowerCountTwoMore(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonDiShouRu1Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonDiShouRu1Count";
        pdValue.Value = thisMonDiShouRu1Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月低收入1人数
        sql = "SELECT dbo.getLowerCount(\'" + thisMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int thisMonDiShouRu2Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonDiShouRu2Count";
        pdValue.Value = thisMonDiShouRu2Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);




        //上月其他家庭数
        sql = "SELECT dbo.getDocOterCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',-1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonOterFamilyCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonOterFamilyCount";
        pdValue.Value = lastMonOterFamilyCount;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //上月其他家庭1数
        sql = "SELECT dbo.getDocOterCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',1,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonOterFamily1Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonOterFamily1Count";
        pdValue.Value = lastMonOterFamily1Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月其他家庭2数
        sql = "SELECT dbo.getDocOterCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',2,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonOterFamily2Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonOterFamily2Count";
        pdValue.Value = lastMonOterFamily2Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月其他家庭3数
        sql = "SELECT dbo.getDocOterCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',3,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonOterFamily3Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonOterFamily3Count";
        pdValue.Value = lastMonOterFamily3Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月其他家庭4数
        sql = "SELECT dbo.getDocOterCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',4,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonOterFamily4Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonOterFamily4Count";
        pdValue.Value = lastMonOterFamily4Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //上月其他家庭5数
        sql = "SELECT dbo.getDocOterCount(\'" + lastMonth.ToString() + "\',\'" + ddlstreetName.ToString() + "\',5,0)";
        //Response.Write(getRedsidyRecordTotalMoneySQL);
        //Response.End();
        int lastMonOterFamily5Count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, sql));
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonOterFamily5Count";
        pdValue.Value = lastMonOterFamily5Count;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);










        ////上月减总数
        //int lastMonCount = lastMonRedCount + lastMonSubCount;
        //paramField = new ParameterField();
        //pdValue = new ParameterDiscreteValue();
        //paramField.ParameterFieldName = "lastMonCount";
        //pdValue.Value = lastMonCount;
        //paramField.CurrentValues.Add(pdValue);
        //paramFields.Add(paramField);

        //上月总金额
        int lastMonMoneySum = lastMonRedMoneySum + lastMonSubMoneySum;
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "lastMonMoneySum";
        pdValue.Value = lastMonMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);

        //本月增加总金额
        int thisMonMoneySum = thisMonRedMoneySum + thisMonSubMoneySum;
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonMoneySum";
        pdValue.Value = thisMonMoneySum;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);






        //本月增加总数
        int thisMonCountAdd = thisMonSubCountAdd + thisMonRedCountAdd;
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonCountAdd";
        pdValue.Value = thisMonCountAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        //本月增加总金额
        int thisMonMoneyAdd = thisMonRedMoneyAdd + thisMonSubMoneyAdd;
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonMoneyAdd";
        pdValue.Value = thisMonMoneyAdd;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);




        ////本月减少总数
        //int thisYearCount = thisYareRedCount + thisYearSubCount;
        //paramField = new ParameterField();
        //pdValue = new ParameterDiscreteValue();
        //paramField.ParameterFieldName = "thisYearCount";
        //pdValue.Value = thisYearCount;
        //paramField.CurrentValues.Add(pdValue);
        //paramFields.Add(paramField);
















        //本月减少总数
        int thisMonCountCut = thisMonRedCountCut + thisMonSubCountCut;
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonCountCut";
        pdValue.Value = thisMonCountCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);



        //本月减少金额
        double thisMonMoneyCut = thisMonRedMoneyCut + thisMonSubMoneyCut;
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName = "thisMonMoneyCut";
        pdValue.Value = thisMonMoneyCut;
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);


        CrystalReportViewer1.ParameterFieldInfo = paramFields;
    }
    public void BindDate()
    {
        int year = Convert.ToInt32(DateTime.Now.Year.ToString());
        for (int i = year - 2; i < year + 3; i++)
        {
            ddlyear.Items.Add(i.ToString());
        }
        ddlyear.SelectedValue = DateTime.Now.Year.ToString();
        ddlmonth.SelectedValue = DateTime.Now.Month.ToString();
    }
    /*public void AddCrystalReport(int numStr,string dataTitle) {
        ParameterFields paramFields = new ParameterFields();
        ParameterField paramField = new ParameterField();
        ParameterDiscreteValue pdValue = new ParameterDiscreteValue();
        paramField = new ParameterField();
        pdValue = new ParameterDiscreteValue();
        paramField.ParameterFieldName ="tkMonth";
        Response.Write(dataTitle);
        pdValue.Value = numStr.ToString();
        paramField.CurrentValues.Add(pdValue);
        paramFields.Add(paramField);
    }
     */
    protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        HTML.Value = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string html=rptHTML.InnerHtml;
        string street=ddlstreet.SelectedValue;
        string effectdate=ddlyear.SelectedValue +ddlmonth.SelectedValue;
        string sql="INSERT INTO  [MonthStatCache] ([HTML] ,[street],[EffectDate]) values ("+html+","+street+","+effectdate+")";
        int i= SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, sql);
        if (i == 1)
            WebHelper.AlertAndRefresh("保存成功");
        else
            WebHelper.Alert("保存失败");

    }
    protected void ddlstreet_SelectedIndexChanged(object sender, EventArgs e)
    {
        HTML.Value = "";
    }
    protected void Button2_ServerClick(object sender, EventArgs e)
    {
        insertCache();
    }
}
